package com.hmall.server.Service.Impl;

import com.hmall.UserClient.UserService;
import com.hmall.annotation.RpcService;
import com.hmall.server.Pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
@Service
@RpcService(group = "test1", version = "version1")
public class UserServiceImpl implements UserService {

    private final ConcurrentHashMap<String, User> userMap;

    public UserServiceImpl() {
        this.userMap = new ConcurrentHashMap<>();
        User admin = User.builder()
                .username("admin")
                .password("123456")
                .phone("13512344321")
                .createTime(LocalDateTime.now().minusHours(2))
                .updateTime(LocalDateTime.now())
                .balance(10000)
                .build();
        userMap.put(admin.getUsername(), admin);
    }

    @Override
    public String getUserInfo(String username) {
        User user = userMap.get(username);
        log.info("UserInfo构建完毕:{}", user);
        return user.toString();
    }
}
